//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.dao.wills;

import com.aidong.dao.wills.BaseDao;
import com.aidong.model.wills.BoxCode;
import com.aidong.model.wills.BoxCodePK;
import org.springframework.stereotype.Repository;

@Repository
public class BoxCodeDao extends BaseDao<BoxCode, BoxCodePK> {
	public BoxCodeDao() {
	}

	public BoxCode getByCode(String shopCode, String code) {
		return (BoxCode)this.getByWhere("shopCode=:p1 and code=:p2", new Object[]{shopCode, code});
	}

	public boolean chkBoxFree(String shopCode, String code) {
		String sql = "select count(*) from BoxRent where shopCode=:p1 and boxCode=:p2 and returnDate is null";
		return ((Integer)this.getBySql(Integer.class, sql, new Object[]{shopCode, code})).intValue() == 0;
	}

	public boolean chkCodeExists(String shopCode, String code1, String code2) {
		String sql = "select count(*) from BoxCode where shopCode=:p1 and code>=:p2 and code<=:p3";
		return ((Integer)this.getBySql(Integer.class, sql, new Object[]{shopCode, code1, code2})).intValue() > 0;
	}

	public boolean updateStatus(BoxCode code, int status) {
		String hql = "update BoxCode set status=:p1 where shopCode=:p2 and code=:p3";
		return this.updateByHql(hql, new Object[]{Integer.valueOf(status), code.getShopCode(), code.getCode()}) > 0;
	}
}
